package org.feng.utils;

/**
 * 名称工具类
 *
 * @author : FengShuai
 * @since : 2024/6/27 9:24
 */
public class NameUtils {
    /**
     * 下划线转驼峰
     *
     * @param str       转换字符串
     * @param firstCase 首字母是否大写
     */
    public static String underlineToCamel(String str, Boolean firstCase) {
        if (str == null || str.isEmpty()) {
            return str;
        }
        StringBuilder sb = new StringBuilder();
        boolean flag = false;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c == '_') {
                flag = true;
            } else {
                if (flag || (firstCase && i == 0)) {
                    sb.append(Character.toUpperCase(c));
                    flag = false;
                } else {
                    sb.append(Character.toLowerCase(c));
                }
            }
        }
        return sb.toString();
    }
}
